package com.example.recyclerviewstudentmessage;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class StudentRViewAdapter extends RecyclerView.Adapter<StudentRViewAdapter.ViewHolder>{
    List<Student> list;
    public StudentRViewAdapter(List<Student> list){
        this.list = list;
    }
    static class ViewHolder extends RecyclerView.ViewHolder{
        TextView tvName,tvAge,tvGrade,tvPhone;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            this.tvName = itemView.findViewById(R.id.tvItemName);
            this.tvAge = itemView.findViewById(R.id.tvItemAge);
            this.tvGrade = itemView.findViewById(R.id.tvItemGrade);
            this.tvPhone = itemView.findViewById(R.id.tvItemPhone);
        }
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ViewHolder viewHolder = new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rv_main_student,parent,false));
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Student student = list.get(position);
        holder.tvName.setText(student.getName());
        holder.tvAge.setText(String.valueOf(student.getAge()));
        holder.tvGrade.setText(student.getGrade());
        holder.tvPhone.setText(student.getPhone());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }


}
